package edu.mapi.ir.viewer;

import java.awt.Shape;
import java.awt.geom.GeneralPath;
import java.awt.geom.Point2D;
import java.util.Vector;

/**
 * @author ZP
 */
public class Wall {

	private double height = 1.0;
	private Vector<Point2D> corners = new Vector<Point2D>();
	private Shape shape = null;
	
	
	public Wall(double height) {
		this.height = height;
	}
	
	public void addCorner(Point2D point) {
		corners.add(point);
		shape = buildShape();
		
	}
	
	public Shape getShape() {
		return shape; 
	}
	
	public Vector<Point2D> getCorners() {
		return corners;
	}
	
	private Shape buildShape() {
		GeneralPath gp = new GeneralPath();
		if (corners.size() <= 1)
			return null;
		
		Point2D first = corners.firstElement();
		gp.moveTo(first.getX(), first.getY());
		
		for (int i = 1; i < corners.size(); i++) {
			Point2D pt = corners.elementAt(i);
			gp.lineTo(pt.getX(), pt.getY());
		}
		
		gp.closePath();
		
		return gp;
	}

	public double getHeight() {
		return height;
	}

	public void setHeight(double height) {
		this.height = height;
	}
	
	@Override
	public String toString() {
		String ret = "\t<Wall Height=\""+getHeight()+"\">\n";
		for (Point2D c : corners) {
			ret += "\t\t<Corner X=\""+c.getX()+"\" Y=\""+c.getY()+"\" />\n";
		}
		return ret+"\t</Wall>\n";
	}
}

